package com.info.zhiduoduo.repository.entity.system;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.info.zhiduoduo.common.utils.DateUtil;

import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@TableName("zdd_month_business_gross")
public class MonthBusinessGross extends Model <MonthBusinessGross> {

	@TableId(value = "id", type = IdType.AUTO)
	private Integer id;
	@ApiModelProperty("当前年份")
	private Integer year;
	@ApiModelProperty("当前季度 1,2,3,4")
	private Integer quarter;
	@ApiModelProperty("当前月份")
	private Integer month;

	@ApiModelProperty(" 交易额")
	private BigDecimal zddAmount;
	@ApiModelProperty("智众包交易额")
	private BigDecimal crowdsourceAmount;
	@ApiModelProperty(" 交易额")
	private BigDecimal taxerAmount;
	@ApiModelProperty("纯代理交易额")
	private BigDecimal agentTaxerAmount;
	@ApiModelProperty("委托接单交易额")
	private BigDecimal entrustAmount;
	@ApiModelProperty("创客团交易额")
	private BigDecimal makerGrouponAmount;
	@ApiModelProperty("交易额小计")
	private BigDecimal monthAmount;

	@ApiModelProperty("服务费")
	private BigDecimal serviceCharge;
	@ApiModelProperty("个税")
	private BigDecimal taxFee;
	@ApiModelProperty("增值税+附加税")
	private BigDecimal valueAddedTax;
	@ApiModelProperty("合伙人佣金")
	private BigDecimal brokerage;
	@ApiModelProperty("合计=服务费+个税+增值税")
	private BigDecimal sum;
	@ApiModelProperty("毛利=服务费-合伙人佣金")
	private BigDecimal gross;

	private Date createtime;
	private Date updatetime;

	public static MonthBusinessGross of(int year, int month) {
		return new MonthBusinessGross().setYear(year).setQuarter(DateUtil.getQuarterOfMonth(month)).setMonth(month);
	}

	public MonthBusinessGross add(MonthBusinessGross other) {
		this.serviceCharge =this.serviceCharge.add(other.serviceCharge);
		this.taxFee = this.taxFee.add(other.taxFee);
		this.valueAddedTax = this.valueAddedTax.add(other.valueAddedTax);
		this.sum = this.sum.add(other.sum);
		return this;
	}

	@Override
	protected Serializable pkVal() {
		return id;
	}

	public void copy(MonthBusinessGross monthBusinessGross) {
		BeanUtils.copyProperties(monthBusinessGross, this, "id");
	}
}
